<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/page.css" rel="stylesheet">
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/admin/js/jquery-ui-1.10.4.custom.min.js"></script>
</head>

<script>
var typeId = {$typeId};
//删除url
var url = "/{$Request.module}/attr";
var deleteUrl = "{:url('attr/delete')}";
</script>

  <script>
  $(document).ready(function(){
      var fixHelperModified = function(e, tr) {
           var $originals = tr.children();
           var $helper = tr.clone();
           $helper.children().each(function(index) {
               $(this).width($originals.eq(index).width())
           });
           return $helper;
       },
       
       updateIndex = function(e, ui) {
           var sort = '';
           var ids = '';
           $('td.index', ui.item.parent()).each(function (i) {
                $(this).html(i + 1);
	            ids+=$(this).attr('shuxing')+',';
	        	sort+=$(this).text()+',';
           });
           ids = ids.substring(0,ids.length-1);
           sort = sort.substring(0,sort.length-1);

	       $.ajax({
	           type:'POST',
	           url:"{:url('attr/paixu')}",
	           data:{'ids':ids,'sort':sort},
	           dataType:'json',
	           success:function(data){
	               layer.msg(data.mess, {icon: 1,time: 1000});
	           },
	           error:function(){
	               layer.msg('操作失败或您没有权限，请重试', {icon: 2,time: 2000});
	           }
	       });
      };

      $("#sort tbody").sortable({
          helper: fixHelperModified,
          stop: updateIndex
      }).disableSelection();
  });
  </script>

<body class="gray-bg">
    <div class="wrapper wrapper-content" id="server">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{$type_name}&nbsp;&nbsp;的属性列表</h5>
                    </div>
                    <div class="ibox-content">
						<div class="row">
						   <div class="col-sm-7 m-b-xs">
                                <a href="{:url('attr/add',array('typeid'=>$typeId))}" class="attradd"><button type="button" class="btn btn-sm btn-primary" id="add"><i class="fa fa-plus" style="color:#FFF;"></i>&nbsp;添加属性</button></a>         
                            </div> 
                                   
                            <div class="col-sm-3" style="float:right;">
                                <select class="form-control m-b" name="typeid">
                                    {foreach name="typeres" item="v"}
                                    <option value="{$v.id}" {if condition="$typeId eq $v['id']"}selected="selected"{/if}>{$v.type_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            
                        </div>  
                                                                      
                        <table id="sort" class="table table-hover table-bordered">
                            <thead>
                                <tr>
                                    <th style="width:25%">属性名称</th>
                                    <th style="width:15%">属性类型</th>
                                    <th style="width:20%">属性可选值</th>
                                    <th style="width:10%">所属类型</th>
                                    <th style="width:15%" class="index">排序</th>
                                    <th style="width:15%">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            {if condition="!empty($list)"}
							{foreach name="list" item="v"} 
                                <tr>
                                    <td>{$v.attr_name}</td>
                                    <td>{if condition="$v['attr_type'] eq 0"}唯一{elseif condition="$v['attr_type'] eq 1"/}单选{/if}</td>
                                    <td>{$v.attr_values}</td>
                                    <td>{$v.type_name}</td>
                                    <td class="index" shuxing="{$v.id}">{$v.sort}</td>
                                    <td><button type="button" class="btn btn-primary btn-xs" onclick="editattr({$v.id},this);"><i class="fa fa-pencil"></i>&nbsp;编辑</button>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-danger btn-xs" onclick="delone({$v.id},this);"><i class="fa fa-close"></i>&nbsp;删除</button></td>
                                </tr>
							{/foreach}
							{else/}
							<tr><td colspan="6" style="text-align:center; font-size:14px;">没有找到相关数据</td></tr>
							{/if}						
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/catecommon.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>
    
    <script>
    /*$(function(){
    	$('#typelst').change(function(){
    		$.ajax({
    			url:url+'/getlst',
    			type:'POST',
    			data:{typeid : $('#typelst').val()},
    			dataType:'json',
    			success:function(data){
    				if(data.status == 1){
    					var html = '';
    					$.each(data.attr,function(index,value){
    						if(value.attr_type == 0){
    							var attrType = '唯一';
    						}else if(value.attr_type == 1){
    							var attrType = '单选';
    						}
    						html+='<tr><td><input type="checkbox" class="text_id" name="id" value="'+value.id+'" /></td><td>'+value.attr_name+'</td><td>'+attrType+'</td><td>'+value.attr_values+'</td><td>'+value.type_name+'</td><td><button type="button" class="btn btn-primary btn-xs edit"><i class="fa fa-pencil"></i>&nbsp;编辑</button>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-danger btn-xs delete"><i class="fa fa-close"></i>&nbsp;删除</button></td></tr>';
    					});
    					$("#attrlst").html(html);
    					$('.attradd').attr('href',url+'/add/typeid/'+data.typeid);
    				}else{
    					var html = data.msg;
    					$('#attrlst').replaceWith("<div id='attrlst'>"+html+"</div>");
    					$('.attradd').attr('href',url+'/add/typeid/'+data.typeid);
    				}
    			}
    		});
    	});
    });*/
    
    $(function(){
        
    	$("#checkAll").click(function () {
            $("input[class='text_id']:checkbox").prop("checked", this.checked);
        });
    	
    	$('select[name=typeid]').change(function(){
    		var type_id = $(this).val();
    		window.location.href = url+'/lst/typeid/'+type_id;
    	});         
    	
    });
    
    //编辑
    function editattr(id,obj){
		layer.open({
			type : 2,
			title : '编辑',
			shadeClose : true,
			shade : 0.5,
			area : ['1000px','650px'],
			content : url+"/edit/id/"+id+'/typeid/'+typeId
		});
    }    

    </script>
</body>
</html>